home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / What's New / • What was new 03⁄98 / Sample Code / Networking / OT PAPServerSample / EnableSelfSendSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-09  |  2.7 KB  |  99 lines  |  [TEXT/CWIE]

  1. /*
  2.     File: EnableSelfSendSample.c
  3.     By:        Rich Kubota
  4.             Developer Technical Support
  5.     
  6.     Purpose: Demonstrate the use of the OTOptionManagement call to tell an AppleTalk
  7.             endpoint to enable/disable the SelfSend option.
  8.             
  9.     change history
  10.         1/8/98 - observed that an option management call to set self send hung under
  11.         OT 1.2.  Modified code so that if OT 1.2 or earlier is detected, then use the 
  12.         classic AppleTalk call - PSetSelfSend to set self send feature.  Also note
  13.         that if the endpoint is async, the same call to PSetSelfSend is made.
  14. */
  15.  
  16. #include "OpenTransport.h"            // open transport files            
  17. #include "OpenTptAppletalk.h"
  18. #include "AppleTalk.h"
  19.  
  20. #define kOTVersion120    0x01208000
  21.  
  22. extern OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend);
  23.  
  24.  
  25. /*
  26.     Sample function to enable/disable the SelfSend option for 
  27.     an AppleTalk endpoint.  This function also demonstrates the
  28.     use of the OTOptionManagement call.
  29.  
  30.     
  31.     Unless explicitely defined by XTI, all Open Transport options
  32.     use a kOTFourByteOptionSize buffer.
  33.         
  34.     Input
  35.     EndpointRef ep - endpoint on which to set SelfSend option on
  36.     long enableSelfSend - 1L - option on, 0L - option off
  37.  
  38.    Return: kOTNoError indicates that the option was successfully negotiated
  39.                OSStatus is an error if < 0, otherwise, the status field is
  40.                returned and is > 0.
  41.     
  42. */
  43. OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend)
  44.  
  45. {
  46.     UInt8            buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  47.     TOption*        opt;                        // option ptr to make items easier to access
  48.     TOptMgmt        req;
  49.     TOptMgmt        ret;
  50.     long            version;
  51.     OSStatus        err;
  52.     SetSelfparms    pb;
  53.     Boolean            usePB = false;
  54.     
  55.     err = Gestalt('otvr', (long*)&version);
  56.     if (version <= kOTVersion120)
  57.         usePB = true;
  58.  
  59.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  60.         usePB = true;
  61.     
  62.     if (usePB == true)
  63.     {
  64.         pb.newSelfFlag = enableSelfSend != 0 ? true : false;  /* set self send option */
  65.         err = PSetSelfSend((MPPPBPtr) &pb, false);
  66.         
  67.     }
  68.     else
  69.     {
  70.         opt = (TOption*)buf;                    // set option ptr to buffer
  71.         req.opt.buf    = buf;
  72.         req.opt.len    = sizeof(buf);
  73.         req.flags    = T_NEGOTIATE;                // negotiate for SelfSend option
  74.  
  75.         ret.opt.buf = buf;
  76.         ret.opt.maxlen = kOTFourByteOptionSize;
  77.         
  78.         opt->level    = ATK_DDP;                    // dealing with DDP
  79.         opt->name    = OPT_SELFSEND;
  80.         opt->len    = kOTFourByteOptionSize;
  81.         opt->status = 0;
  82.         *(UInt32*)opt->value = enableSelfSend;        // set the desired option level, true or false
  83.  
  84.         DebugStr("\p About to call Option management");    
  85.         err = OTOptionManagement(ep, &req, &ret);
  86.         
  87.             // if no error then return the option status value
  88.         if (err == kOTNoError)
  89.         {
  90.             if (opt->status != T_SUCCESS)
  91.                 err = opt->status;
  92.             else
  93.                 err = kOTNoError;
  94.         }
  95.     }
  96.         
  97.     return err;
  98. }
  99.